"""
请求对象的定制
"""

import urllib.request


url = "https://www.baidu.com"

"""
url的组成：
    http/https  +  主机地址（域名）  +  端口号  +  路径  +  参数  +  锚点

http    80
https   443
mysql   3306
oracle  1521
redis   6379
mongodb 27017
"""

# 伪装成正常游览器
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.50"
}

# 请求对象定制
request = urllib.request.Request(url=url, headers=headers)

response = urllib.request.urlopen(request)
content = response.read()
print(content.decode("utf-8"))
